
<?php 
$productArr = $product->show_product();
if(isset($_GET['productID']))
{
	$productID =$_GET['productID'];
	$product->delete($productID);
	header("Location: index.php");
}

?>
<script>
	$(function() {
		$( "#datepicker" ).datepicker({dateFormat:'mm-dd-yy'});
		
	});
	</script>
<style>
<!--
.totalblue
{
	color:blue;
	font-weight:bold;
}
.totared
{
	color:blue;
	font-weight:bold;
}
-->
</style>	
<div class="content-admin">
<div class="product-title">List Product</div>
<tr>
	<th>Hello :<?php  echo $_SESSION['username_admin']?> / <a href ="logout.php" style="text-decoration: none"> Logout</a><br></th>
	<th>&nbsp</th>
</tr>
<div class="demo">
	<form action="index.php?func=listPro" method="post">
		Date: <input id="datepicker" type="text" name ="datetime" value="<?php if(isset($_POST['datetime'])) echo $_POST['datetime'];?>">
		<input type="submit" name="btn_filter" value="Filter" class=" button mws-button blue" style="padding:4px 9px !important;">
	</form>
</div>
<tr>
	<th>&nbsp</th>
</tr>
<?php 
	if(isset($_POST['btn_filter']))
	{
		$date = $_POST['datetime'];	
?>
		<div class="mws-panel-body"> 
			<table class="mws-datatable-fn mws-table">			
					<thead>									
						<tr>
							<th colspan="1" rowspan="1" class="sorting">Tool</th>
							<th colspan="1" rowspan="1" class="sorting">Product Name</th>
							<th colspan="1" rowspan="1" class="sorting">Image</th>
							<th colspan="1" rowspan="1" class="sorting">Voted</th>
						</tr>
		           </thead>
		                            
		          <tbody>
		          <?php 
		          	foreach($productArr as $product)
		          	{
		           ?>
		          	<tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
		                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
		                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
		                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
		                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
		                <td class="center"><a href="index.php?func=editProduct&proID=<?php echo $product['productID']?>" style="text-decoration: none">Edit </a>/ <a href="index.php?func=listPro&productID=<?php echo $product['productID']?>" style="text-decoration: none" onclick="return confirm('Are you sure?');">Delete</a></td>
		                <td class="center"><?php echo $product['productName']?></td>
		            	<td class="center"><img src="<?php echo $product['proImg']?>"></td>
		            	<td class="center">
							<?php
								$productOption = new productOption();
								$productID =$product['productID'];
								$productOptionAll = $productOption->show_product_option_by_product($productID);
							?>
							
							<table border="0" width="200px">
								<?php foreach ($productOptionAll as $productOption)
									{?>
								<tr>
								
									<td style="text-align:right;">
										<?php echo $productOption['title']?> :
									</td>
									<td style="text-align:left;">
									<?php 
										$total = $productVote->count_product_vote_by_proID_and_title_and_date($productID, $productOption['title'],$_POST['datetime']); 
										if($total['total'] > 0)
											echo "<font class='totalblue'>".$total['total']."</font>";
										else 
											echo $total['total'];
										?><br />
									</td>
								</tr>
								<?php }?>
								
							</table>
						</td>
		            	
		            </tr>
		          <?php }?>
		          </tbody>
		      </table>	  		
			</div>
<?php }else{?>
		<div class="mws-panel-body"> 		
			<table class="mws-datatable-fn mws-table">				
					<thead>									
						<tr>
							<th colspan="1" rowspan="1" class="sorting">Tool</th>
							<th colspan="1" rowspan="1" class="sorting">Product Name</th>
							<th colspan="1" rowspan="1" class="sorting">Image</th>
							<th colspan="1" rowspan="1" class="sorting">Voted</th>
							<th colspan="1" rowspan="1" class="sorting">Date</th>
						</tr>
		           </thead>		                            
		          <tbody>
		          <?php 
		          	foreach($productArr as $product)
		          	{
		           ?>
		          	<tr class="gradeA odd"  id="f_row_{$k}" class="class_tr" 
		                	onmouseout="onMouseOutRow('f_','{$k}','#f7f9fb','#FEFFE8');" 
		                	onmouseover="onMouseOverRow('f_','{$k}','#FEFFC8', '#FEFFE8');" 
		                	onclick="onMouseClickRow('f_','{$k}','#FEFFE8', '#ffffff', '#f7f9fb');" 
		                	style="background: none repeat scroll 0% 0% rgb(247, 249, 251); text-align: center;">
		                <td class="center"><a href="index.php?func=editProduct&proID=<?php echo $product['productID']?>" style="text-decoration: none">Edit </a>/ <a href="index.php?func=listPro&productID=<?php echo $product['productID']?>" style="text-decoration: none" onclick="return confirm('Are you sure?');">Delete</a></td>
		                <td class="center"><?php echo $product['productName']?></td>
		            	<td class="center"><img src="<?php echo $product['proImg']?>"></td>
		            	<td class="center"><?php include 'voted.php';?></td>
		            	<td class="center">
		            		<?php 
		            			$date = $productVote->show_product_vote_by_proID_and_date($product['productID']);
								echo $date['voteTime'];?>
						</td>
		            </tr>
		          <?php }?>
		          </tbody>
		      </table>	  		
		</div>	
<?php }?>
<tr>
	<th>&nbsp</th>
</tr>
</div>
